/**
 * Definition for a binary tree node.
 */

function TreeNode(val) {
  this.val = val;
  this.left = this.right = null;
}
/**
 * @param {TreeNode} root
 * @return {TreeNode}
 */
var mirrorTree = function (root) {
  if (root) {
    let tmp = root.left
    root.left = root.right
    root.right = tmp
    if (root.left) {
      mirrorTree(root.left)
    }
    if (root.right) {
      mirrorTree(root.right)
    }
  }
  return root
};